<?php

/**
 * File theme.inc
 *
 * includes hook_theme() functions and all of its executions.
 */

/**
 * implements hook_theme().
 *
 * Customize user login / user register / user pass functions
 */
function crabii_theme() {
  $items = array();
  $path = drupal_get_path('theme', 'crabii') . '/templates/forms';

  $items['user_login'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'user-login',
    'preprocess functions' => array(
      'crabii_preprocess_user_login'
    ),
  );
  $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'user-register-form',
    'preprocess functions' => array(
      'crabii_preprocess_user_register_form'
    ),
  );
  $items['user_pass'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'user-pass',
    'preprocess functions' => array(
      'crabii_preprocess_user_pass'
    ),
  );

  $items['nip_node_form'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'nip-node-form',
  );

  $items['confirm_form'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'confirm-form',
  );

  $items['user_profile_form'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'user-profile-form',
    'preprocess functions' => array(
      'crabii_preprocess_user_profile_form'
    ),
  );

  $items['change_pwd_page_form'] = array(
    'render element' => 'form',
    'path' => $path,
    'template' => 'change-pwd-page-form',
    'preprocess functions' => array(
      'crabii_preprocess_change_pwd_page_form'
    ),
  );

  return $items;
}

/**
 * helper function for changing user pages (login/registration/pass).
 */
function user_inc_preprocess_page(&$vars) {
  if(in_array(current_path(), array('user', 'user/login', 'user/password', 'user/register', 'node/add/nip'))) {
    $vars['theme_hook_suggestions'][] = 'page__simple';

    // For disabling message-printing on PAGE displays
    $vars['show_messages'] = FALSE;
  }
}

/**
 * preprocess function for user login
 * @param $vars
 */
function crabii_preprocess_user_login(&$vars) {
  $form = &$vars['form'];
  _transform_horizontal_form($form);
}

/**
 * preprocess function for user register
 * @param $vars
 */
function crabii_preprocess_user_register_form(&$vars) {
  $form = &$vars['form'];
  _transform_horizontal_form($form);
  $vars['messages'] = theme('status_messages');
}

/**
 * preprocess function for user pass
 * @param $vars
 */
function crabii_preprocess_user_pass(&$vars) {
  $form = &$vars['form'];
  _transform_horizontal_form($form);
  $vars['messages'] = theme('status_messages');
}

/**
 * preprocess function for user login
 * @param $vars
 */
function crabii_preprocess_user_profile_form(&$vars) {
  $form = &$vars['form'];
  _transform_horizontal_form($form);
  $vars['messages'] = theme('status_messages');
}

/**
 * preprocess function for change password form
 * @param $vars
 */
function crabii_preprocess_change_pwd_page_form(&$vars) {
  $form = &$vars['form'];
  _transform_horizontal_form($form);
  $vars['messages'] = theme('status_messages');
}
